package com.wzy.level.detail.detailServlet;

import com.wzy.Jdbc封装.pojo.News_detail;
import com.wzy.level.detail.detailService.detailService;
import com.wzy.level.detail.detailServiceImpl.detailServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/detail")
public class detail extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        detailService detail = new detailServiceImpl();
        List<News_detail> news_details1 = detail.selectAll();

        HttpSession session = req.getSession();
        int count = (int) session.getAttribute("count");
        int total = news_details1.size();
        session.setAttribute("total",total);
        int totalPage =0;
        try {
            totalPage = (int)total/count;
        }catch (Exception e){
            e.printStackTrace();
        }
//        session.setAttribute("count1",count);

        session.setAttribute("totalPage",totalPage);
//    session.setAttribute("total_detail",news_details1);


        List<News_detail> news_details = (List<News_detail>) session.getAttribute("news_detail");
        session.setAttribute("news_details",news_details);
        System.out.println(req.getContextPath());

        resp.sendRedirect(req.getContextPath()+"/system/detail.jsp");
    }

}
